home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / recog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-12  |  28.1 KB  |  1,102 lines

  1. /* Subroutines used by or related to instruction recognition.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include <stdio.h>
  24. #include "insn-config.h"
  25. #include "recog.h"
  26. #include "regs.h"
  27. #include "hard-reg-set.h"
  28. #include "real.h"
  29.  
  30.  
  31. static int inequality_comparisons_p ();
  32. int strict_memory_address_p ();
  33. int memory_address_p ();
  34.  
  35. /* Nonzero means allow operands to be volatile.
  36.    This is 1 if you use recog_memoized, 0 if you don't.
  37.    init_recog and recog_memoized are responsible for setting it.
  38.    This way of handling it is not really clean and will be change later.  */
  39.  
  40. int volatile_ok;
  41.  
  42. rtx recog_addr_dummy;
  43.  
  44. /* On return from `constrain_operands', indicate which alternative
  45.    was satisfied.  */
  46.  
  47. int which_alternative;
  48.  
  49. /* Nonzero after end of reload pass.
  50.    Set to 1 or 0 by toplev.c.
  51.    Controls the significance of (SUBREG (MEM)).  */
  52.  
  53. int reload_completed;
  54.  
  55. /* Initialize data used by the function `recog'.
  56.    This must be called once in the compilation of a function
  57.    before any insn recognition may be done in the function.  */
  58.  
  59. void
  60. init_recog ()
  61. {
  62.   volatile_ok = 0;
  63.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  64. }
  65.  
  66. /* Try recognizing the instruction INSN,
  67.    and return the code number that results.
  68.    Remeber the code so that repeated calls do not
  69.    need to spend the time for actual rerecognition.
  70.  
  71.    This function is the normal interface to instruction recognition.
  72.    The automatically-generated function `recog' is normally called
  73.    through this one.  (The only exception is in combine.c.)  */
  74.  
  75. int
  76. recog_memoized (insn)
  77.      rtx insn;
  78. {
  79.   volatile_ok = 1;
  80.   if (INSN_CODE (insn) < 0)
  81.     INSN_CODE (insn) = recog (PATTERN (insn), insn);
  82.   return INSN_CODE (insn);
  83. }
  84.  
  85. /* Return 1 if the insn following INSN does not contain
  86.    any ordered tests applied to the condition codes.
  87.    EQ and NE tests do not count.  */
  88.  
  89. int
  90. next_insn_tests_no_inequality (insn)
  91.      rtx insn;
  92. {
  93.   register rtx next = NEXT_INSN (insn);
  94.  
  95.   return ((GET_CODE (next) == JUMP_INSN
  96.        || GET_CODE (next) == INSN
  97.        || GET_CODE (next) == CALL_INSN)
  98.       && ! inequality_comparisons_p (PATTERN (next)));
  99. }
  100.  
  101. /* Return 1 if the CC value set up by INSN is not used.  */
  102.  
  103. int
  104. next_insns_test_no_inequality (insn)
  105.      rtx insn;
  106. {
  107.   register rtx next = NEXT_INSN (insn);
  108.  
  109.   for (; next != 0; next = NEXT_INSN (next))
  110.     {
  111.       if (GET_CODE (next) == CODE_LABEL
  112.       || GET_CODE (next) == BARRIER)
  113.     return 1;
  114.       if (GET_CODE (next) == NOTE)
  115.     continue;
  116.       if (inequality_comparisons_p (PATTERN (next)))
  117.     return 0;
  118.       if (GET_CODE (PATTERN (next)) == SET
  119.       && SET_DEST (PATTERN (next)) == cc0_rtx)
  120.     return 1;
  121.       if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
  122.     return 1;
  123.     }
  124.   return 1;
  125. }
  126.  
  127. static int
  128. inequality_comparisons_p (x)
  129.      rtx x;
  130. {
  131.   register char *fmt;
  132.   register int len, i;
  133.   register enum rtx_code code = GET_CODE (x);
  134.  
  135.   switch (code)
  136.     {
  137.     case REG:
  138.     case PC:
  139.     case CC0:
  140.     case CONST_INT:
  141.     case CONST_DOUBLE:
  142.     case CONST:
  143.     case LABEL_REF:
  144.     case SYMBOL_REF:
  145.       return 0;
  146.  
  147.     case LT:
  148.     case LTU:
  149.     case GT:
  150.     case GTU:
  151.     case LE:
  152.     case LEU:
  153.     case GE:
  154.     case GEU:
  155.       return (XEXP (x, 0) == cc0_rtx || XEXP (x, 1) == cc0_rtx);
  156.     }
  157.  
  158.   len = GET_RTX_LENGTH (code);
  159.   fmt = GET_RTX_FORMAT (code);
  160.  
  161.   for (i = 0; i < len; i++)
  162.     {
  163.       if (fmt[i] == 'e')
  164.     {
  165.       if (inequality_comparisons_p (XEXP (x, i)))
  166.         return 1;
  167.     }
  168.       else if (fmt[i] == 'E')
  169.     {
  170.       register int j;
  171.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  172.         if (inequality_comparisons_p (XVECEXP (x, i, j)))
  173.           return 1;
  174.     }
  175.     }
  176.         
  177.   return 0;
  178. }
  179.  
  180. /* Return 1 if OP is a valid general operand for machine mode MODE.
  181.    This is either a register reference, a memory reference,
  182.    or a constant.  In the case of a memory reference, the address
  183.    is checked for general validity for the target machine.
  184.  
  185.    Register and memory references must have mode MODE in order to be valid,
  186.    but some constants have no machine mode and are valid for any mode.
  187.  
  188.    If MODE is VOIDmode, OP is checked for validity for whatever mode
  189.    it has.
  190.  
  191.    The main use of this function is as a predicate in match_operand
  192.    expressions in the machine description.  */
  193.  
  194. int
  195. general_operand (op, mode)
  196.      register rtx op;
  197.      enum machine_mode mode;
  198. {
  199.   register enum rtx_code code = GET_CODE (op);
  200.   int mode_altering_drug = 0;
  201.  
  202.   if (mode == VOIDmode)
  203.     mode = GET_MODE (op);
  204.  
  205.   if (CONSTANT_P (op))
  206.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  207.         && LEGITIMATE_CONSTANT_P (op));
  208.  
  209.   /* Except for certain constants with VOIDmode, already checked for,
  210.      OP's mode must match MODE if MODE specifies a mode.  */
  211.  
  212.   if (GET_MODE (op) != mode)
  213.     return 0;
  214.  
  215.   while (code == SUBREG)
  216.     {
  217.       op = SUBREG_REG (op);
  218.       code = GET_CODE (op);
  219. #if 0
  220.       /* No longer needed, since (SUBREG (MEM...))
  221.      will load the MEM into a reload reg in the MEM's own mode.  */
  222.       mode_altering_drug = 1;
  223. #endif
  224.     }
  225.   if (code == REG)
  226.     return 1;
  227.   if (code == CONST_DOUBLE)
  228.     return LEGITIMATE_CONSTANT_P (op);
  229.   if (code == MEM)
  230.     {
  231.       register rtx y = XEXP (op, 0);
  232.       if (! volatile_ok && MEM_VOLATILE_P (op))
  233.     return 0;
  234.       /* Use the mem's mode, since it will be reloaded thus.  */
  235.       mode = GET_MODE (op);
  236.       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
  237.     }
  238.   return 0;
  239.  
  240.  win:
  241.   if (mode_altering_drug)
  242.     return ! mode_dependent_address_p (XEXP (op, 0));
  243.   return 1;
  244. }
  245.  
  246. /* Return 1 if OP is a valid memory address for a memory reference
  247.    of mode MODE.
  248.  
  249.    The main use of this function is as a predicate in match_operand
  250.    expressions in the machine description.  */
  251.  
  252. int
  253. address_operand (op, mode)
  254.      register rtx op;
  255.      enum machine_mode mode;
  256. {
  257.   return memory_address_p (mode, op);
  258. }
  259.  
  260. /* Return 1 if OP is a register reference of mode MODE.
  261.    If MODE is VOIDmode, accept a register in any mode.
  262.  
  263.    The main use of this function is as a predicate in match_operand
  264.    expressions in the machine description.  */
  265.  
  266. int
  267. register_operand (op, mode)
  268.      register rtx op;
  269.      enum machine_mode mode;
  270. {
  271.   if (GET_MODE (op) != mode && mode != VOIDmode)
  272.     return 0;
  273.  
  274.   if (GET_CODE (op) == SUBREG)
  275.     {
  276.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  277.      because it is guaranteed to be reloaded into one.
  278.      Just make sure the MEM is valid in itself.
  279.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  280.      but currently it does result from (SUBREG (REG)...) where the
  281.      reg went on the stack.)  */
  282.       if (! reload_completed)
  283.     return general_operand (op, mode);
  284.     }
  285.  
  286.   while (GET_CODE (op) == SUBREG)
  287.     op = SUBREG_REG (op);
  288.  
  289.   return GET_CODE (op) == REG;
  290. }
  291.  
  292. /* Return 1 if OP is a valid immediate operand for mode MODE.
  293.  
  294.    The main use of this function is as a predicate in match_operand
  295.    expressions in the machine description.  */
  296.  
  297. int
  298. immediate_operand (op, mode)
  299.      register rtx op;
  300.      enum machine_mode mode;
  301. {
  302.   return ((CONSTANT_P (op)
  303.        || (GET_CODE (op) == CONST_DOUBLE
  304.            && (GET_MODE (op) == mode || mode == VOIDmode)))
  305.       && LEGITIMATE_CONSTANT_P (op));
  306. }
  307.  
  308. /* Return 1 if OP is a general operand that is not an immediate operand.  */
  309.  
  310. int
  311. nonimmediate_operand (op, mode)
  312.      register rtx op;
  313.      enum machine_mode mode;
  314. {
  315.   return (general_operand (op, mode)
  316.       && ! CONSTANT_P (op) && GET_CODE (op) != CONST_DOUBLE);
  317. }
  318.  
  319. /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
  320.  
  321. int
  322. nonmemory_operand (op, mode)
  323.      register rtx op;
  324.      enum machine_mode mode;
  325. {
  326.   if (CONSTANT_P (op) || GET_CODE (op) == CONST_DOUBLE)
  327.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  328.         && LEGITIMATE_CONSTANT_P (op));
  329.  
  330.   if (GET_MODE (op) != mode && mode != VOIDmode)
  331.     return 0;
  332.  
  333.   if (GET_CODE (op) == SUBREG)
  334.     {
  335.       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
  336.      because it is guaranteed to be reloaded into one.
  337.      Just make sure the MEM is valid in itself.
  338.      (Ideally, (SUBREG (MEM)...) should not exist after reload,
  339.      but currently it does result from (SUBREG (REG)...) where the
  340.      reg went on the stack.)  */
  341.       if (! reload_completed)
  342.     return general_operand (op, mode);
  343.     }
  344.  
  345.   while (GET_CODE (op) == SUBREG)
  346.     op = SUBREG_REG (op);
  347.  
  348.   return GET_CODE (op) == REG;
  349. }
  350.  
  351. /* Return 1 if OP is a valid operand that stands for pushing a
  352.    value of mode MODE onto the stack.
  353.  
  354.    The main use of this function is as a predicate in match_operand
  355.    expressions in the machine description.  */
  356.  
  357. int
  358. push_operand (op, mode)
  359.      rtx op;
  360.      enum machine_mode mode;
  361. {
  362.   if (GET_CODE (op) != MEM)
  363.     return 0;
  364.  
  365.   if (GET_MODE (op) != mode)
  366.     return 0;
  367.  
  368.   op = XEXP (op, 0);
  369.  
  370. #ifdef STACK_GROWS_DOWNWARD
  371.   if (GET_CODE (op) != PRE_DEC)
  372.     return 0;
  373. #else
  374.   if (GET_CODE (op) != PRE_INC)
  375.     return 0;
  376. #endif
  377.   return XEXP (op, 0) == stack_pointer_rtx;
  378. }
  379.  
  380. /* Return 1 if ADDR is a valid memory address for mode MODE.  */
  381.  
  382. int
  383. memory_address_p (mode, addr)
  384.      enum machine_mode mode;
  385.      register rtx addr;
  386. {
  387.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  388.   return 0;
  389.  
  390.  win:
  391.   return 1;
  392. }
  393.  
  394. /* Return 1 if OP is a valid memory reference with mode MODE,
  395.    including a valid address.
  396.  
  397.    The main use of this function is as a predicate in match_operand
  398.    expressions in the machine description.  */
  399.  
  400. int
  401. memory_operand (op, mode)
  402.      register rtx op;
  403.      enum machine_mode mode;
  404. {
  405.   rtx inner;
  406.   int mode_altering_drug = 0;
  407.  
  408.   if (! reload_completed)
  409.     /* Note that no SUBREG is a memory operand before end of reload pass,
  410.        because (SUBREG (MEM...)) forces reloading into a register.  */
  411.     return GET_CODE (op) == MEM && general_operand (op, mode);
  412.  
  413.   if (mode != VOIDmode && GET_MODE (op) != mode)
  414.     return 0;
  415.  
  416.   inner = op;
  417.   while (GET_CODE (inner) == SUBREG)
  418.     inner = SUBREG_REG (inner);
  419.  
  420.   return (GET_CODE (inner) == MEM && general_operand (op, mode));
  421. }
  422.  
  423. /* Return 1 if OP is a valid indirect memory reference with mode MODE;
  424.    that is, a memory reference whose address is a general_operand.  */
  425.  
  426. int
  427. indirect_operand (op, mode)
  428.      register rtx op;
  429.      enum machine_mode mode;
  430. {
  431.   return (GET_MODE (op) == mode && memory_operand (op, mode)
  432.       && general_operand (XEXP (op, 0), Pmode));
  433. }
  434.  
  435. /* If BODY is an insn body that uses ASM_OPERANDS,
  436.    return the number of operands (both input and output) in the insn.
  437.    Otherwise return -1.  */
  438.  
  439. int
  440. asm_noperands (body)
  441.      rtx body;
  442. {
  443.   if (GET_CODE (body) == ASM_OPERANDS)
  444.     /* No output operands: return number of input operands.  */
  445.     return XVECLEN (body, 3);
  446.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  447.     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
  448.     return XVECLEN (SET_SRC (body), 3) + 1;
  449.   else if (GET_CODE (body) == PARALLEL
  450.        && GET_CODE (XVECEXP (body, 0, 0)) == SET
  451.        && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
  452.     {
  453.       /* Multiple output operands, or 1 output plus some clobbers:
  454.      body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...].  */
  455.       int i;
  456.       int n_sets;
  457.  
  458.       /* Count backwards through CLOBBERs to determine number of SETs.  */
  459.       for (i = XVECLEN (body, 0); i > 0; i--)
  460.     {
  461.       if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
  462.         break;
  463.       if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
  464.         return -1;
  465.     }
  466.  
  467.       /* N_SETS is now number of output operands.  */
  468.       n_sets = i;
  469.  
  470.       /* Verify that all the SETs we have
  471.      came from a single original asm_operands insn
  472.      (so that invalid combinations are blocked).  */
  473.       for (i = 0; i < n_sets; i++)
  474.     {
  475.       rtx elt = XVECEXP (body, 0, i);
  476.       if (GET_CODE (elt) != SET)
  477.         return -1;
  478.       if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
  479.         return -1;
  480.       /* If these ASM_OPERANDS rtx's came from different original insns
  481.          then they aren't allowed together.  */
  482.       if (XVEC (SET_SRC (elt), 3)
  483.           != XVEC (SET_SRC (XVECEXP (body, 0, 0)), 3))
  484.         return -1;
  485.     }
  486.       return XVECLEN (SET_SRC (XVECEXP (body, 0, 0)), 3) + n_sets;
  487.     }
  488.   else if (GET_CODE (body) == PARALLEL
  489.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  490.     {
  491.       /* 0 outputs, but some clobbers:
  492.      body is [(asm_operands ...) (clobber (reg ...))...].  */
  493.       int i;
  494.       int n_sets;
  495.  
  496.       /* Make sure all the other parallel things really are clobbers.  */
  497.       for (i = XVECLEN (body, 0) - 1; i > 0; i--)
  498.     if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
  499.       return -1;
  500.  
  501.       return XVECLEN (XVECEXP (body, 0, 0), 3);
  502.     }
  503.   else
  504.     return -1;
  505. }
  506.  
  507. /* Assuming BODY is an insn body that uses ASM_OPERANDS,
  508.    copy its operands (both input and output) into the vector OPERANDS,
  509.    the locations of the operands within the insn into the vector OPERAND_LOCS,
  510.    and the constraints for the operands into CONSTRAINTS.
  511.    Write the modes of the operands into MODES.
  512.    Return the assembler-template.
  513.  
  514.    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
  515.    we don't store that info.  */
  516.  
  517. char *
  518. decode_asm_operands (body, operands, operand_locs, constraints, modes)
  519.      rtx body;
  520.      rtx *operands;
  521.      rtx **operand_locs;
  522.      char **constraints;
  523.      enum machine_mode *modes;
  524. {
  525.   register int i;
  526.   int noperands;
  527.   char *template = 0;
  528.  
  529.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  530.     {
  531.       rtx asmop = SET_SRC (body);
  532.       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
  533.  
  534.       noperands = XVECLEN (asmop, 3) + 1;
  535.  
  536.       /* The input operands are found in the 1st element vector.  */
  537.       /* Constraints for inputs are in the 2nd element vector.  */
  538.       for (i = 1; i < noperands; i++)
  539.     {
  540.       if (operand_locs)
  541.         operand_locs[i] = &XVECEXP (asmop, 3, i - 1);
  542.       if (operands)
  543.         operands[i] = XVECEXP (asmop, 3, i - 1);
  544.       if (constraints)
  545.         constraints[i] = XSTR (XVECEXP (asmop, 4, i - 1), 0);
  546.       if (modes)
  547.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i - 1));
  548.     }
  549.  
  550.       /* The output is in the SET.
  551.      Its constraint is in the ASM_OPERANDS itself.  */
  552.       if (operands)
  553.     operands[0] = SET_DEST (body);
  554.       if (operand_locs)
  555.     operand_locs[0] = &SET_DEST (body);
  556.       if (constraints)
  557.     constraints[0] = XSTR (asmop, 1);
  558.       if (modes)
  559.     modes[0] = GET_MODE (SET_DEST (body));
  560.       template = XSTR (asmop, 0);
  561.     }
  562.   else if (GET_CODE (body) == ASM_OPERANDS)
  563.     {
  564.       rtx asmop = body;
  565.       /* No output operands: BODY is (asm_operands ....).  */
  566.  
  567.       noperands = XVECLEN (asmop, 3);
  568.  
  569.       /* The input operands are found in the 1st element vector.  */
  570.       /* Constraints for inputs are in the 2nd element vector.  */
  571.       for (i = 0; i < noperands; i++)
  572.     {
  573.       if (operand_locs)
  574.         operand_locs[i] = &XVECEXP (asmop, 3, i);
  575.       if (operands)
  576.         operands[i] = XVECEXP (asmop, 3, i);
  577.       if (constraints)
  578.         constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
  579.       if (modes)
  580.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
  581.     }
  582.       template = XSTR (asmop, 0);
  583.     }
  584.   else if (GET_CODE (body) == PARALLEL
  585.        && GET_CODE (XVECEXP (body, 0, 0)) == SET)
  586.     {
  587.       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
  588.       int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs.  */
  589.       int nin = XVECLEN (asmop, 3);
  590.       int nout = 0;        /* Does not include CLOBBERs.  */
  591.  
  592.       /* At least one output, plus some CLOBBERs.  */
  593.  
  594.       /* The outputs are in the SETs.
  595.      Their constraints are in the ASM_OPERANDS itself.  */
  596.       for (i = 0; i < nparallel; i++)
  597.     {
  598.       if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
  599.         break;        /* Past last SET */
  600.       
  601.       if (operands)
  602.         operands[i] = SET_DEST (XVECEXP (body, 0, i));
  603.       if (operand_locs)
  604.         operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
  605.       if (constraints)
  606.         constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
  607.       if (modes)
  608.         modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
  609.       nout++;
  610.     }
  611.  
  612.       /* The input operands are found in the 1st element vector.  */
  613.       /* Constraints for inputs are in the 2nd element vector.  */
  614.       for (i = 0; i < nin; i++)
  615.     {
  616.       if (operand_locs)
  617.         operand_locs[i + nout] = &XVECEXP (asmop, 3, i);
  618.       if (operands)
  619.         operands[i + nout] = XVECEXP (asmop, 3, i);
  620.       if (constraints)
  621.         constraints[i + nout] = XSTR (XVECEXP (asmop, 4, i), 0);
  622.       if (modes)
  623.         modes[i + nout] = GET_MODE (XVECEXP (asmop, 4, i));
  624.     }
  625.  
  626.       template = XSTR (asmop, 0);
  627.     }
  628.   else if (GET_CODE (body) == PARALLEL
  629.        && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
  630.     {
  631.       /* No outputs, but some CLOBBERs.  */
  632.  
  633.       rtx asmop = XVECEXP (body, 0, 0);
  634.       int nin = XVECLEN (asmop, 3);
  635.  
  636.       /* The input operands are found in the 1st element vector.  */
  637.       /* Constraints for inputs are in the 2nd element vector.  */
  638.       for (i = 0; i < nin; i++)
  639.     {
  640.       if (operand_locs)
  641.         operand_locs[i] = &XVECEXP (asmop, 3, i);
  642.       if (operands)
  643.         operands[i] = XVECEXP (asmop, 3, i);
  644.       if (constraints)
  645.         constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
  646.       if (modes)
  647.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
  648.     }
  649.  
  650.       template = XSTR (asmop, 0);
  651.     }
  652.  
  653.   return template;
  654. }
  655.  
  656. extern rtx plus_constant ();
  657. extern rtx copy_rtx ();
  658.  
  659. /* Given an rtx *P, if it is a sum containing an integer constant term,
  660.    return the location (type rtx *) of the pointer to that constant term.
  661.    Otherwise, return a null pointer.  */
  662.  
  663. static rtx *
  664. find_constant_term_loc (p)
  665.      rtx *p;
  666. {
  667.   register rtx *tem;
  668.   register enum rtx_code code = GET_CODE (*p);
  669.  
  670.   /* If *P IS such a constant term, P is its location.  */
  671.  
  672.   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
  673.       || code == CONST)
  674.     return p;
  675.  
  676.   /* Otherwise, if not a sum, it has no constant term.  */
  677.  
  678.   if (GET_CODE (*p) != PLUS)
  679.     return 0;
  680.  
  681.   /* If one of the summands is constant, return its location.  */
  682.  
  683.   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
  684.       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
  685.     return p;
  686.  
  687.   /* Otherwise, check each summand for containing a constant term.  */
  688.  
  689.   if (XEXP (*p, 0) != 0)
  690.     {
  691.       tem = find_constant_term_loc (&XEXP (*p, 0));
  692.       if (tem != 0)
  693.     return tem;
  694.     }
  695.  
  696.   if (XEXP (*p, 1) != 0)
  697.     {
  698.       tem = find_constant_term_loc (&XEXP (*p, 1));
  699.       if (tem != 0)
  700.     return tem;
  701.     }
  702.  
  703.   return 0;
  704. }
  705.  
  706. /* Return 1 if OP is a memory reference
  707.    whose address contains no side effects
  708.    and remains valid after the addition
  709.    of a positive integer less than the
  710.    size of the object being referenced.
  711.  
  712.    We assume that the original address is valid and do not check it.
  713.  
  714.    This uses strict_memory_address_p as a subroutine, so
  715.    don't use it before reload.  */
  716.  
  717. int
  718. offsettable_memref_p (op)
  719.      rtx op;
  720. {
  721.   return ((GET_CODE (op) == MEM)
  722.       && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
  723. }
  724.  
  725. /* Return 1 if Y is a memory address which contains no side effects
  726.    and would remain valid for mode MODE
  727.    after the addition of a positive integer less than the
  728.    size of that mode.
  729.  
  730.    We assume that the original address is valid and do not check it.
  731.  
  732.    If STRICTP is nonzero, we require a strictly valid address,
  733.    for the sake of use in reload.c.  */
  734.  
  735. int
  736. offsettable_address_p (strictp, mode, y)
  737.      int strictp;
  738.      enum machine_mode mode;
  739.      register rtx y;
  740. {
  741.   register enum rtx_code ycode = GET_CODE (y);
  742.   register rtx z;
  743.   rtx y1 = y;
  744.   rtx *y2;
  745.   int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
  746.  
  747.   if (CONSTANT_ADDRESS_P (y))
  748.     return 1;
  749.       
  750.   /* If the expression contains a constant term,
  751.      see if it remains valid when max possible offset is added.  */
  752.  
  753.   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
  754.     {
  755.       int old = INTVAL (y1 = *y2);
  756.       int good;
  757.       INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
  758.       good = (*addressp) (mode, y);
  759.       /* In any case, restore old contents of memory.  */
  760.       INTVAL (y1) = old;
  761.       return good;
  762.     }
  763.  
  764.   if (ycode == PRE_DEC || ycode == PRE_INC
  765.       || ycode == POST_DEC || ycode == POST_INC)
  766.     return 0;
  767.  
  768.   /* The offset added here is chosen as the maximum offset that
  769.      any instruction could need to add when operating on something
  770.      of the specified mode.  We assume that if Y and Y+c are
  771.      valid addresses then so is Y+d for all 0<d<c.  */
  772.  
  773.   z = plus_constant (y, GET_MODE_SIZE (mode) - 1);
  774.  
  775.   return (*addressp) (mode, z);
  776. }
  777.  
  778. /* Return 1 if ADDR is an address-expression whose effect depends
  779.    on the mode of the memory reference it is used in.
  780.  
  781.    Autoincrement addressing is a typical example of mode-dependence
  782.    because the amount of the increment depends on the mode.  */
  783.  
  784. int
  785. mode_dependent_address_p (addr)
  786.      rtx addr;
  787. {
  788.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
  789.   return 0;
  790.  win:
  791.   return 1;
  792. }
  793.  
  794. /* Return 1 if OP is a general operand
  795.    other than a memory ref with a mode dependent address.  */
  796.  
  797. int
  798. mode_independent_operand (op, mode)
  799.      enum machine_mode mode;
  800.      rtx op;
  801. {
  802.   rtx addr;
  803.  
  804.   if (! general_operand (op, mode))
  805.     return 0;
  806.  
  807.   if (GET_CODE (op) != MEM)
  808.     return 1;
  809.  
  810.   addr = XEXP (op, 0);
  811.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
  812.   return 1;
  813.  lose:
  814.   return 0;
  815. }
  816.  
  817. /* Given an operand OP that is a valid memory reference
  818.    which satisfies offsettable_memref_p,
  819.    return a new memory reference whose address has been adjusted by OFFSET.
  820.    OFFSET should be positive and less than the size of the object referenced.
  821. */
  822.  
  823. rtx
  824. adj_offsettable_operand (op, offset)
  825.      rtx op;
  826.      int offset;
  827. {
  828.   register enum rtx_code code = GET_CODE (op);
  829.  
  830.   if (code == MEM) 
  831.     {
  832.       register rtx y = XEXP (op, 0);
  833.  
  834.       if (CONSTANT_ADDRESS_P (y))
  835.     return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  836.  
  837.       if (GET_CODE (y) == PLUS)
  838.     {
  839.       rtx z = y;
  840.       register rtx *const_loc;
  841.  
  842.       op = copy_rtx (op);
  843.       z = XEXP (op, 0);
  844.       const_loc = find_constant_term_loc (&z);
  845.       if (const_loc)
  846.         {
  847.           *const_loc = plus_constant (*const_loc, offset);
  848.           return op;
  849.         }
  850.     }
  851.  
  852.       return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  853.     }
  854.   abort ();
  855. }
  856.  
  857. #ifdef REGISTER_CONSTRAINTS
  858.  
  859. /* Check the operands of an insn (found in recog_operands)
  860.    against the insn's operand constraints (found via INSN_CODE_NUM)
  861.    and return 1 if they are valid.
  862.  
  863.    WHICH_ALTERNATIVE is set to a number which indicates which
  864.    alternative of constraints was matched: 0 for the first alternative,
  865.    1 for the next, etc.
  866.  
  867.    In addition, when two operands are match
  868.    and it happens that the output operand is (reg) while the
  869.    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
  870.    make the output operand look like the input.
  871.    This is because the output operand is the one the template will print.
  872.  
  873.    This is used in final, just before printing the assembler code.  */
  874.  
  875. struct funny_match
  876. {
  877.   int this, other;
  878. };
  879.  
  880. int
  881. constrain_operands (insn_code_num)
  882.      int insn_code_num;
  883. {
  884.   char *constraints[MAX_RECOG_OPERANDS];
  885.   register int c;
  886.   int noperands = insn_n_operands[insn_code_num];
  887.  
  888.   struct funny_match funny_match[MAX_RECOG_OPERANDS];
  889.   int funny_match_index;
  890.   int nalternatives = insn_n_alternatives[insn_code_num];
  891.  
  892.   if (noperands == 0 || nalternatives == 0)
  893.     return 1;
  894.  
  895.   for (c = 0; c < noperands; c++)
  896.     constraints[c] = insn_operand_constraint[insn_code_num][c];
  897.  
  898.   which_alternative = 0;
  899.  
  900.   while (which_alternative < nalternatives)
  901.     {
  902.       register int opno;
  903.       int lose = 0;
  904.       funny_match_index = 0;
  905.  
  906.       for (opno = 0; opno < noperands; opno++)
  907.     {
  908.       register rtx op = recog_operand[opno];
  909.       register char *p = constraints[opno];
  910.       int win = 0;
  911.       int val;
  912.  
  913.       /* `alter_subreg' should already have converted any SUBREG
  914.          that appears at the level of an operand.  */
  915.       while (GET_CODE (op) == SUBREG)
  916.         abort ();
  917.  
  918.       /* An empty constraint or empty alternative
  919.          allows anything which matched the pattern.  */
  920.       if (*p == 0 || *p == ',')
  921.         win = 1;
  922.  
  923.       while (*p && (c = *p++) != ',')
  924.         switch (c)
  925.           {
  926.           case '=':
  927.           case '+':
  928.           case '?':
  929.           case '#':
  930.           case '&':
  931.           case '!':
  932.           case '*':
  933.           case '%':
  934.         break;
  935.  
  936.           case '0':
  937.           case '1':
  938.           case '2':
  939.           case '3':
  940.           case '4':
  941.         /* This operand must be the same as a previous one.  */
  942.         /* This kind of constraint is used for instructions such
  943.            as add when they take only two operands.  */
  944.         /* Note that the lower-numbered operand is passed first.  */
  945.         val = operands_match_p (recog_operand[c - '0'],
  946.                     recog_operand[opno]);
  947.         if (val != 0)
  948.           win = 1;
  949.         /* If output is *x and input is *--x,
  950.            arrange later to change the output to *--x as well,
  951.            since the output op is the one that will be printed.  */
  952.         if (val == 2)
  953.           {
  954.             funny_match[funny_match_index].this = opno;
  955.             funny_match[funny_match_index++].other = c - '0';
  956.           }
  957.         break;
  958.  
  959.           case 'p':
  960.         /* p is used for address_operands, and everything
  961.            that must be checked was checked already.  */
  962.         win = 1;
  963.         break;
  964.  
  965.         /* No need to check general_operand again;
  966.            it was done in insn-recog.c.  */
  967.           case 'g':
  968.         /* Anything goes unless it is a REG and really has a hard reg
  969.            but the hard reg is not in the class GENERAL_REGS.  */
  970.         if (GENERAL_REGS == ALL_REGS
  971.             || GET_CODE (op) != REG
  972.             || reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op)))
  973.           win = 1;
  974.         break;
  975.  
  976.           case 'r':
  977.         if (GET_CODE (op) == REG
  978.             && (GENERAL_REGS == ALL_REGS
  979.             || reg_fits_class_p (op, GENERAL_REGS, 0, GET_MODE (op))))
  980.           win = 1;
  981.         break;
  982.  
  983.           case 'm':
  984.         if (GET_CODE (op) == MEM)
  985.           win = 1;
  986.         break;
  987.  
  988.           case '<':
  989.         if (GET_CODE (op) == MEM
  990.             && (GET_CODE (XEXP (op, 0)) == PRE_DEC
  991.             || GET_CODE (XEXP (op, 0)) == POST_DEC))
  992.           win = 1;
  993.         break;
  994.  
  995.           case '>':
  996.         if (GET_CODE (op) == MEM
  997.             && (GET_CODE (XEXP (op, 0)) == PRE_INC
  998.             || GET_CODE (XEXP (op, 0)) == POST_INC))
  999.           win = 1;
  1000.         break;
  1001.  
  1002.           case 'F':
  1003.         if (GET_CODE (op) == CONST_DOUBLE)
  1004.           win = 1;
  1005.         break;
  1006.  
  1007.           case 'G':
  1008.           case 'H':
  1009.         if (GET_CODE (op) == CONST_DOUBLE
  1010.             && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
  1011.           win = 1;
  1012.         break;
  1013.  
  1014.           case 's':
  1015.         if (GET_CODE (op) == CONST_INT)
  1016.           break;
  1017.           case 'i':
  1018.         if (CONSTANT_P (op))
  1019.           win = 1;
  1020.         break;
  1021.  
  1022.           case 'n':
  1023.         if (GET_CODE (op) == CONST_INT)
  1024.           win = 1;
  1025.         break;
  1026.  
  1027.           case 'I':
  1028.           case 'J':
  1029.           case 'K':
  1030.           case 'L':
  1031.           case 'M':
  1032.         if (GET_CODE (op) == CONST_INT
  1033.             && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
  1034.           win = 1;
  1035.         break;
  1036.  
  1037.           case 'o':
  1038.         if (offsettable_memref_p (op))
  1039.           win = 1;
  1040.         break;
  1041.  
  1042.           default:
  1043.         if (GET_CODE (op) == REG
  1044.             && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
  1045.                      0, GET_MODE (op)))
  1046.           win = 1;
  1047.           }
  1048.  
  1049.       constraints[opno] = p;
  1050.       /* If this operand did not win somehow,
  1051.          this alternative loses.  */
  1052.       if (! win)
  1053.         lose = 1;
  1054.     }
  1055.       /* This alternative won; the operands are ok.
  1056.      Change whichever operands this alternative says to change.  */
  1057.       if (! lose)
  1058.     {
  1059.       while (--funny_match_index >= 0)
  1060.         {
  1061.           recog_operand[funny_match[funny_match_index].other]
  1062.         = recog_operand[funny_match[funny_match_index].this];
  1063.         }
  1064.       return 1;
  1065.     }
  1066.  
  1067.       which_alternative++;
  1068.     }
  1069.   return 0;
  1070. }
  1071.  
  1072. /* Return 1 iff OPERAND (assumed to be a REG rtx)
  1073.    is a hard reg in class CLASS when its regno is offsetted by OFFSET
  1074.    and changed to mode MODE.
  1075.    If REG occupies multiple hard regs, all of them must be in CLASS.  */
  1076.  
  1077. int
  1078. reg_fits_class_p (operand, class, offset, mode)
  1079.      rtx operand;
  1080.      register enum reg_class class;
  1081.      int offset;
  1082.      enum machine_mode mode;
  1083. {
  1084.   register int regno = REGNO (operand);
  1085.   if (regno < FIRST_PSEUDO_REGISTER
  1086.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1087.                 regno + offset))
  1088.     {
  1089.       register int sr;
  1090.       regno += offset;
  1091.       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
  1092.        sr > 0; sr--)
  1093.     if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  1094.                  regno + sr))
  1095.       break;
  1096.       return sr == 0;
  1097.     }
  1098.   return 0;
  1099. }
  1100.  
  1101. #endif /* REGISTER_CONSTRAINTS */
  1102.